<template>
  <div class="search_body">
    <div class="search_input">
      <div class="search_input_wrapper">
        <i class="iconfont icon-sousuo"></i>
        <input type="text" v-model="message" />
      </div>
    </div>
    <div class="search_result">
      <h3>电影/电视剧/综艺</h3>
      <ul class="movieList">
        <li class="mov" v-for="item in moviesList" :key="item.id">
          <div class="img">
            <img :src="item.img | setWH('128.180')" />
          </div>
          <div class="info">
            <p>
              <span>{{ item.nm }}</span>
              <span v-if="item.sc">{{ item.sc }}</span>
              <span v-else>{{ item.wish }}</span>
            </p>
            <p v-if="item.enm">{{ item.enm }}</p>
            <p>{{ item.cat }}</p>
            <p>{{ item.rt }}</p>
            <div class="btn_mall">购票</div>
          </div>
        </li>
      </ul>
      <ul class="cinemasList">
        <h3>影院</h3>
        <li v-for="item in cinemaList" :key="item.id">
          <div class="title">
            <h4>{{ item.nm }}</h4>
            <div class="price">
              <span>{{ item.sellPrice }}</span>元起
            </div>
          </div>
          <div class="address">
            {{ item.addr }}
            <span>{{ item.distance }}</span>
          </div>
          <p class="cip">
            <span>座</span>
            <span v-if="item.hallType[0]">杜比全景声厅</span>
            <span v-if="item.hallType[1]">4k厅</span>
            <span v-if="item.hallType[2]">巨幕厅</span>
            <span v-if="item.allowRefund">退</span>
            <span v-if="item.endorse">改签</span>
            <span class="last" v-if="item.snack">小吃</span>
          </p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: "Search",
  data() {
    return {
      message: "",
      moviesList: [],
      cinemaList: [],
    };
  },
  methods: {
    //axios请求防抖
    /*  cancelRequest() {
      if (typeof this.source === "function") {
        this.source("终止请求");
      }
    }, */
  },

  watch: {
    //监听数据的变化
    message(value) {
      var that = this;
      var cityId = this.$store.state.city.id;
      var message = encodeURI(this.message);
      //   this.axios({
      //     url:
      //       "https://m.maizuo.com/gateway?cityId=440300&ticketFlag=0&k=7401314",
      //     headers: {
      //       "X-Client-Info":
      //         '{"a": "3000","ch": "1002","v": "5.0.4","e": "1599439552343623153483778","bc": "110100"}',
      //       "X-Host": "mall.film-ticket.cinema.list",
      //     },
      //   }).then((res) => {
      //     /*  console.log(res); */
      //     var msg = res.data.msg;
      //     var movies = res.data.data.movies;
      //     if (msg && movies) {
      //       this.moviesList = res.data.data.movies.list;
      //     }
      //   });
      /* this.axios.get("/ajax/cinemaDetail?cinemaId=890").then((res) => {
      console.log(res);
    }); */
      // 请求影院数据和电影数据
      this.$nextTick(() => {
        this.axios
          .get("/ajax/search?kw=" + message + "&cityId=" + cityId + "&stype=-1")
          .then((res) => {
            console.log(res);
            const moviesList = res.data.movies;
            const cinemaList = res.data.cinemas;
            if (moviesList && moviesList.list) {
              this.moviesList = moviesList.list;
            }
            if (cinemaList && cinemaList.list) {
              this.moviesList = cinemaList.list;
            }
            console.log(this.moviesList);
            console.log(this.cinemaList);
            console.log(this.moviesList.length);
          });
      });
    },
  },
};
</script>

<style scoped lang="scss">
#content .search_body {
  flex: 1;
  overflow: auto;
  background-color: #fff;
  padding-top: 55px;
}
.search_body .search_input {
  padding: 8px 10px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #e5e5e5;
}
.search_body .search_input_wrapper {
  padding: 0 10px;
  border: 1px solid #e6e6e6;
  border-radius: 5px;
  background-color: #fff;
  display: flex;
  line-height: 20px;
}
.search_body .search_input_wrapper i {
  font-size: 16px;
  padding: 4px 0;
}
.search_body .search_input_wrapper input {
  border: none;
  font-size: 13px;
  color: #333;
  padding: 4px 0;
  outline: none;
  margin-left: 5px;
  width: 100%;
}
.search_body .search_result h3 {
  font-size: 15px;
  color: #999;
  padding: 9px 15px;
  border-bottom: 1px solid #e6e6e6;
}
.search_body .search_result li {
  border-bottom: 1px #c9c9c9 dashed;
  padding: 10px 15px;
  min-height: 90px;
  box-sizing: border-box;
}
.mov {
  position: relative;
  display: flex;
}
.search_body .search_result .img {
  width: 60px;
  float: left;
}
.search_body .search_result .img img {
  width: 100%;
}
.search_body .search_result .info {
  float: left;
  margin-left: 15px;
  flex: 1;
}
.search_body .search_result .info p {
  width: 80%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  height: 22px;
  display: flex;
  line-height: 22px;
  font-size: 12px;
}
.search_body .search_result .info p:nth-of-type(1) span:nth-of-type(1) {
  font-size: 18px;
  flex: 1;
}
.search_body .search_result .info p:nth-of-type(1) span:nth-of-type(2) {
  font-size: 16px;
  color: #fc7103;
}

.movieList {
  display: block;
  height: 320px;
  overflow: hidden;
  border-bottom: 1px solid #e6e6e6;
}
/* .search_body .movieList li {
  display: block !important;
} */
.title {
  width: 100%;
  font-size: 11px;
  color: #999;
  overflow: hidden;
  margin-bottom: 6px;
  h4 {
    float: left;
    color: #000;
    font-size: 16px;
    margin-right: 10px;
  }
  .price {
    width: 100%;

    font-size: 12px;
    span {
      color: #ef4238;
      font-size: 17px;
      margin-right: 5px;
    }
  }
}
.address {
  width: 100%;
  display: flex;
  justify-content: space-between;
  color: #999;
}
.cip {
  width: 100%;
  margin-top: 7px;
  span {
    border: 1px solid #589daf;
    color: #589daf;
    font-size: 12px;
    position: relative;
    display: inline-block;
    padding: 0 3px;
    height: 15px;
    line-height: 15px;
    border-radius: 2px;
    margin: 0 2px;
    &.last {
      color: #ff9900;
      border: 1px solid #ff9900;
    }
  }
}
.btn_mall {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 8px;
  width: 47px;
  height: 27px;
  line-height: 28px;
  text-align: center;
  background-color: #f03d37;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
</style>
